<template>
    <div id="regist">
        <div id="">

            <div></div>
            <div></div>

        </div>
        <div class="fa fa-chevron-left" id="back" @click="backClick"></div>
        <div id="regist-title">
            快速注册
        </div>

        <input type="text" placeholder="请输入用户名" v-model="username" >
        <input type="password" placeholder="请输入密码" v-model="psw">
        <input type="text" placeholder="请输入手机号" v-model="tel">
        <input type="text" placeholder="请输入邮箱" v-model="email">
        <br>
        <button @click="registClick" :disabled="isNull" :class="{'background':isNull}">注册</button>
        <div>{{registThen}}</div>
        <div>{{judgeNull}}</div>
        <div>{{registShow}}</div>
        <Toast v-model="setRegistShow">{{registThen}}</Toast>

    </div>

    
</template>

<script>
import {Toast} from "vux";
export default {
    components: {
        Toast,  
    },
    data:function(){
        return {
            username:"",
            psw:"",
            tel:"",
            email:"",
            isNull:true,
            setRegistShow:false,
        }
    },
    methods: {
        backClick:function(){
            history.back();
        },
        registClick:function(){
            var data = {
                username:this.username,
                psw:this.psw,
                tel:this.tel,
                email:this.email
            };
            this.$store.dispatch("requestRegist",data);
        }
    },
    computed: {
        registThen:function(){
            
           return this.$store.state.registThen.msg;
        },
        registShow:function(){
            
          this.setRegistShow = this.$store.state.registShow;
          setTimeout(function(){
              this.setRegistShow = false;
          })
        },
        judgeNull:function(){
            var reg = /^[A-Za-z0-9\u4e00-\u9fa5_]+$/;
            var reg1 = /^[a-zA-Z\d_]{4,}$/;
            var reg2 = /^1[3|4|5|8][0-9]\d{4,8}$/;
            var reg3 = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
            if(!reg.test(this.username)){
                this.isNull = true;
            }else  if(!reg1.test(this.psw)){
                this.isNull = true;
            }else  if(!reg2.test(this.tel)){
                this.isNull = true;
            }else if(!reg3.test(this.email)){
                this.isNull = true;
            }else{
                this.isNull = false;
            } 
        }
    },

}
</script>

<style scoped>
#regist{
    background-color: #cccccc;
    height: 100vh;
}
#regist-title{
    text-align: center;
    font-size: 15px;
    height: 45px;
    line-height: 45px;
    background-color: skyblue;
    font-family: 宋体;
    font-weight: 700;
}
#back{
    position: absolute;
    height: 4px;
    line-height: 45px;
    left: 15px;
}
#regist input{
height: 45px;
width: 95%;
margin-left: 8px;
margin-top: 10px;
padding: 10px;
}
button{
    height: 45px;
    width: 95%;
    margin-left: 8px;
    margin-top: 10px;
    padding: 10px;
    background-color: deepskyblue;
    border-radius: 5px;
}
.background{
    background-color: #999999;
}
</style>